#include <bits/stdc++.h>
using namespace std;
#define int long long

int n, k, a[100005];
vector<int> pos[100005];
vector<array<int, 4>> upds[100005];

struct Info {
	int val, cnt;
	Info operator+ (const Info &i) const {
		if (val == i.val) return {val, i.cnt + cnt};
		if (val < i.val) return *this;
		return i;
	}
};
struct SGT {
#define ls(p) (p << 1)
#define rs(p) (p << 1 | 1)
	Info res[100005*4];
	int tagad[100005*4];
	inline void push_up(int i) {
		res[i] = res[ls(i)] + res[rs(i)];
	}
	inline void build(int i, int l, int r) {
		if (l == r){
			res[i] = {0, 1};
			return;
		}
		int mid = (l + r) / 2;
		build(ls(i), l, mid);
		build(rs(i), mid + 1, r);
		push_up(i);
	}
	inline void settag(int i, int v) {
		tagad[i] += v;
		res[i].val += v;
	}
	inline void push_down(int i) {
		if (!tagad[i]) return;
		settag(ls(i), tagad[i]);
		settag(rs(i), tagad[i]);
		tagad[i] = 0;
	}
	inline void update(int i, int l, int r, int ql, int qr, int v) {
		if (l > qr || r < ql) return;
		if (l >= ql && r <= qr) return settag(i, v);
		int mid = (l + r) / 2; push_down(i);
		update(ls(i), l, mid, ql, qr, v);
		update(rs(i), mid + 1, r, ql, qr, v);
		push_up(i);
	}
} d[16];

signed main() {
	freopen("reporter.in", "r", stdin); freopen("reporter.out", "w", stdout);
	ios::sync_with_stdio(0); cin.tie(0);
	cin >> n >> k;
	for (int i = 1; i <= n; ++i) {
		cin >> a[i];
		pos[a[i]].push_back(i);
	}
	for (int fk = 0; fk < (1 << k); ++fk) d[fk].build(1, 1, n);
	for (int i = 1; i <= n; ++i) {
		for (int ks = 1; ks <= k; ++ks) {
			if (ks > pos[i].size()) continue;
			for (int j = ks - 1; j < pos[i].size(); ++j) {
				int lef_l = (j == ks - 1 ? 1 : pos[i][j - ks] + 1);
				int lef_r = pos[i][j - ks + 1];
				int rgt_l = pos[i][j];
				int rgt_r = (j == pos[i].size() - 1 ? n : pos[i][j + 1] - 1);
				upds[rgt_l].push_back({lef_l, lef_r, ks, 1});
				upds[rgt_r + 1].push_back({lef_l, lef_r, ks, -1});
			}
		}
	}
	int ans = 0;
	for (int i = 1; i <= n; ++i) {
		for (auto j : upds[i]) {
			for (int fk = 0; fk < (1 << k); ++fk) {
				if (fk & (1 << (j[2] - 1))) {
					d[fk].update(1, 1, n, j[0], j[1], j[3]);
				}
			}
		}
		int tmp = 0;
		for (int fk = 0; fk < (1 << k); ++fk) {
			int w = __builtin_parity(fk) ? 1 : -1;
			if (d[fk].res[1].val == 0) {
				tmp += w * (i - d[fk].res[1].cnt); 
			} else {
				tmp += w * i; 
			}
		}
//		cout << i << " " << tmp << "\n";
		ans += tmp;
	}
	cout << ans << "\n";
	return 0;
}
